package com.thb.business.service.Impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thb.business.dao.IArticleStoreDao;
import com.thb.business.model.Article;
import com.thb.business.model.ArticleStore;
import com.thb.business.service.IArticleStoreService;
import com.thb.exception.ExceptionCodeUtil;
import com.thb.exception.ServiceException;

@Service
public class ArticleStoreServiceImpl implements IArticleStoreService {
	
	Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private IArticleStoreDao articleStoreDao;

	@Override
	public List<Article> findByPara(ArticleStore para) {
		return articleStoreDao.findByPara(para);
	}
	
	@Override
	public int countByPara(ArticleStore para) {
		return articleStoreDao.countByPara(para);
	}

	@Override
	public int addStore(ArticleStore para) {
		List<Article> asList = findByPara(para);
		if(asList.size() > 0){
			throw new ServiceException(ExceptionCodeUtil.CommonErrorCode, "文章已经收藏");
		}
		return add(para);
	}

	@Override
	public int deleteStore(ArticleStore para) {
		
		return articleStoreDao.delete(para);
	}
	
	private int add(ArticleStore para){
		return articleStoreDao.add(para);
	}

	

}
